import logging

from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.webdriver import WebDriver


class BasePage:
    def __init__(self,driver:WebDriver=None):
        self.driver = driver
    def log_info(self, message):
        logging.info(message)

    def find(self,by,value):
        self.log_info('find')
        self.log_info(by)
        self.log_info(value)
        #查找元素
        return  self.driver.find_element(by,value)

    def find_and_click(self,by,value):
        self.log_info("find_and_click")
        #查找元素后点击
        self.find(by,value).click()

    def find_and_sendkeys(self,by,value,text):
        self.log_info("find_and_sendkeys")
        #查找元素后添加
        self.find(by, value).send_keys(text)

    def get_toast_text(self):
        result = self.driver.find_element(MobileBy.XPATH, "//*[@class='android.widget.Toast']").get_attribute('text')
        return result